// pages/qiye_jieshao/qiye_jieshao.js
const app = getApp()
//获得全局js变量
var util = require('../../utils/util.js');

var WxParse = require('../../wxParse/wxParse.js');
Page({
  data: {
    isShow: true,
    keywords: '',
    year: '',
    month: '',
    userinfo: [],
    list: [],
    allnum: '',
    ispLayer: false,
    pass: '',
    sureOrderId: 0
  },
  bindDateChange: function(e) {
    var date = e.detail.value;
    var arr = date.split('-');
    this.setData({
      year: arr[0],
      month:arr[1]
    })

    this.getinfo();
  },
  onLoad: function (options) {
    var date = new Date();
    this.setData({
      year: date.getFullYear(),
      month: date.getMonth() + 1
    });
    this.data.month = (this.data.month > 10)? this.data.month : '0' + this.data.month;
    wx.setNavigationBarTitle({
      title: '全部订单'
    });
    this.data.id = options.id;
    this.data.userinfo = wx.getStorageSync('user');
    this.getinfo();
  },
  inputKeywords: function (e) {
    this.setData({
      keywords: e.detail.value
    });
  },
  inputPass: function (e) {
    this.setData({
      pass: e.detail.value
    });
  },
  copynum: function (e) {
    var str = e.currentTarget.dataset.item.logNumber;
    wx.setClipboardData({
      data: str,
      success: function () {
        wx.showToast({
          title: '复制成功',
          icon: 'none'
        });
      }
    });
  },
  surepass: function () {
    if (this.data.pass == '' || this.data.pass == null || this.data.pass == undefined) {
      wx.showToast({
        icon: 'none',
        title: '请输入核销码'
      });
      return;
    }
    var that = this;
    util.httpRrquest(app.data.apiurl + 'mallshop/orderSure', 'GET', {pass: this.data.pass,
        sureOrderId: this.data.sureOrderId})
    .then(function (response) {
        if (response.code == -1) {
          return;
        } else {
          that.setData({
            ispLayer: false
          });
          that.getinfo();
        }
    }, function (error) {
        console.log(error);
    })
  },
  showPicker: function () {
    // 这里的选择器逻辑需要根据微信小程序的 picker 组件进行调整
    // 暂时保留，你可能需要进一步处理
    this.setData({
      isShow:!this.data.isShow
    });
  },
  onConfirm: function (res, type) {
    this.setData({
      isShow:!this.data.isShow
    });
    switch (type) {
      case "date":
        this.setData({
          year: res.obj.year,
          month: res.obj.month
        });
        break;
    }
    this.getinfo();
  },
  onCancel: function () {
    this.setData({
      isShow:!this.data.isShow
    });
  },
  getinfo: function () {
    var that = this;
    util.httpRrquest(app.data.apiurl + 'mallshop/getOrderTongji', 'GET', {id: that.data.id,
        keywords: this.data.keywords,
        month: this.data.month,
        year: this.data.year})
    .then(function (response) {
        var data = response.data.data;
        that.setData({
          info: data.info,
          allnum: data.allnum,
          list: data.list
        });
    }, function (error) {
        console.log(error);
    })
  },
  hexiao: function (e) {
    this.setData({
      sureOrderId: e.currentTarget.dataset.id,
      ispLayer: true
    });
  },
  closeLayer: function () {
    this.setData({
      ispLayer: false
    });
  }
});